package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.entity.WhOutOrderRecord;
import cn.stylefeng.guns.modular.order.mapper.WhOutOrderRecordMapper;
import cn.stylefeng.guns.modular.order.model.params.WhOutOrderRecordParam;
import cn.stylefeng.guns.modular.order.model.result.WhOutOrderRecordResult;
import  cn.stylefeng.guns.modular.order.service.WhOutOrderRecordService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 武汉出库快递单合单记录 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-10-13
 */
@Service
public class WhOutOrderRecordServiceImpl extends ServiceImpl<WhOutOrderRecordMapper, WhOutOrderRecord> implements WhOutOrderRecordService {

    @Override
    public void add(WhOutOrderRecordParam param){
        WhOutOrderRecord entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(WhOutOrderRecordParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(WhOutOrderRecordParam param){
        WhOutOrderRecord oldEntity = getOldEntity(param);
        WhOutOrderRecord newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public WhOutOrderRecordResult findBySpec(WhOutOrderRecordParam param){
        return null;
    }

    @Override
    public List<WhOutOrderRecordResult> findListBySpec(WhOutOrderRecordParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(WhOutOrderRecordParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(WhOutOrderRecordParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private WhOutOrderRecord getOldEntity(WhOutOrderRecordParam param) {
        return this.getById(getKey(param));
    }

    private WhOutOrderRecord getEntity(WhOutOrderRecordParam param) {
        WhOutOrderRecord entity = new WhOutOrderRecord();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
